package com.example.rwq_test.designParttern.multiThread.threadSpecificStorage;

import java.io.FileNotFoundException;
import java.io.PrintWriter;

/**
 * 线程特有的日志类
 *
 * @author renweiqiang
 * @version 1.0.0
 * @createTime 2022/11/19
 */
public class ThreadSpecificLog {
    private PrintWriter writer = null;

    /**
     * 初始化writer字段
     */
    public ThreadSpecificLog(String fileName) {
        try {
            writer = new PrintWriter(fileName);
        } catch (FileNotFoundException e) {
        }
    }

    /**
     * 写日志
     */
    public void printIn(String context) {
        writer.println(context);
    }

    /**
     * 关闭日志
     */
    public void close() {
        writer.println("=== END of LOG===");
        writer.close();
    }
}
